<?php
namespace StarCloud\Library\Factory;

use StarCloud\Library\Exception;
use StarCloud\Library\Sdk\Wechat;

class WechatFactory
{
    const APP_NAME_1 = 'huoshi'; // 火石养殖

    public static $instances = [];
    const CONFIGS = [
        self::APP_NAME_1 => [
            'token'=>'huoshi', //填写你设定的key
            'encodingaeskey'=>'2frpn7ESThb7HatdgzSAQ5jL87Wn6gV62OQLUrBBT0Y', //填写加密用的EncodingAESKey
            'appid'=>'wx90275296d5e08ee2', //填写高级调用功能的app id
            'appsecret'=>'739ea4eee0e0a40b4c8569ed0056086c' //填写高级调用功能的密钥
        ],

    ];

    public static function getWechatInstance($app) : Wechat
    {
        if (!isset(self::CONFIGS[$app])) {
            throw new Exception(10001);
        }

        if (empty(self::$instances[$app])) {
            self::$instances[$app] = new Wechat(self::CONFIGS[$app]);
        }

        return self::$instances[$app];
    }
}
